﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using eTMS.Controllers;
using eTMS.Controllers.KhoaHocService;
using eTMS.Controllers.KhoaService;
using eTMS.Controllers.LopService;
using eTMS.Controllers.NganhHocService;
namespace eTMS.UserControls
{
    public partial class TreeKhoaNganhKhoaHoc : UserControl
    {
        public TreeKhoaNganhKhoaHoc()
        {
            InitializeComponent();
        }
        public bool IsShowAllKhoa
        {
            set
            {
                comboBoxKhoaHoc1.IsAddAllItem = value;
            }
            get
            {
                return comboBoxKhoaHoc1.IsAddAllItem;
            }
        }
        public bool IsShowSoSVToiDaLop
        {
            set
            {
                treeKhoaNganh1.IsShowSoSVToiDaLop = value;
            }
        }
        public event EventHandler OnChangeKhoaHoc;
        public event EventHandler OnChangeTreeSelected;
        public void InitData()
        {
            KhoaHocController.LoadAllKhoaHoc(false);
            NganhHocController.LoadAllNganhHoc(false);
            KhoaController.LoadAllKhoa(false);
            comboBoxKhoaHoc1.BindData();
        }
        private bool _IsShowNganh = true;
        public bool IsShowNganh
        {
            set
            {
                treeKhoaNganh1.IsShowNganh = value;
            }
        }
        private bool _IsShowLop = true;
        public bool IsShowLop
        {
            set
            {
                treeKhoaNganh1.IsShowLop = value;
            }
        }
        public int KhoaHoc_ID
        {
            get
            {
                if (comboBoxKhoaHoc1.SelectedIndex < 0) return -1;
                return (int)comboBoxKhoaHoc1.SelectedValue;
            }
            set
            {
                comboBoxKhoaHoc1.SelectedValue = value;
            }
        }
        public KhoaHocEntity GetKhoaHoc()
        {
            if (comboBoxKhoaHoc1.SelectedIndex < 0) return null;
            return (KhoaHocEntity)comboBoxKhoaHoc1.SelectedItem;
        }
        public void UpdateToScreen()
        {
            treeKhoaNganh1.UpdateToScreen();
        }

        public int SelectedKhoa_ID
        {
            get
            {
                return treeKhoaNganh1.SelectedKhoa_ID;
            }
        }

        public KhoaEntity GetSelectedKhoa()
        {
            return treeKhoaNganh1.SelectedKhoa;
        }
        public int SelectedNganhHoc_ID
        {
            get
            {
                return treeKhoaNganh1.SelectedNganhHoc_ID;
            }
        }
        public NganhHocEntity GetSelectedNganhHoc()
        {
            return treeKhoaNganh1.SelectedNganhHoc;
        }

        public int SelectedLop_ID
        {
            get
            {
                return treeKhoaNganh1.SelectedLop_ID;
            }
            set
            {
                _Lop_ID = value;
            }
        }
        private int _Lop_ID = 0;
        public List<DataRow> GetSelectedListDataRowLop()
        {
            return treeKhoaNganh1.GetSelectedListDataRowLop();
        }
        public List<LopEntity> GetSelectedListLop()
        {
            return treeKhoaNganh1.GetSelectedListLop();
        }
        public void RemoveSelectedListLop()
        {
            treeKhoaNganh1.RemoveSelectedListLop();
        }
        public LopEntity GetSelectedLop()
        {
            return treeKhoaNganh1.SelectedLop;
        }
        public void UpdateLopNodeText()
        {
            treeKhoaNganh1.UpdateLopNodeText();
        }
        public int CurrentNganhHoc_ID
        {
            get
            {
                return treeKhoaNganh1.CurrentNganhHoc_ID;
            }
        }

        private void TreeKhoaNganhKhoaHoc_Load(object sender, EventArgs e)
        {
            if (DesignMode) return;
            comboBoxKhoaHoc1.SelectedValueChanged += new EventHandler(comboBoxKhoaHoc1_SelectedValueChanged);
            //KhoaHocController.LoadAllKhoaHoc(false);
            //comboBoxKhoaHoc1.BindData();
            if (_Lop_ID > 0)
                treeKhoaNganh1.SelectedLop_ID = _Lop_ID;
        }
        private void BindDataTree()
        {
            if (DesignMode) return;
            try
            {
                treeKhoaNganh1.KhoaHoc_ID = (int)comboBoxKhoaHoc1.SelectedValue;
                treeKhoaNganh1.UpdateToScreen();
            }
            catch
            {

            }
        }
        private void comboBoxKhoaHoc1_SelectedValueChanged(object sender, EventArgs e)
        {
            if (comboBoxKhoaHoc1.SelectedIndex < 0) return;
            BindDataTree();
            if (OnChangeKhoaHoc != null)
            {
                OnChangeKhoaHoc(sender, e);
            }
        }
        public string HeaderText
        {
            set
            {
                groupBox1.Text = value;
            }
            get
            {
                return groupBox1.Text;
            }
        }
        private void treeKhoaNganh1_OnChangeTreeSelected(object sender, EventArgs e)
        {
            if (OnChangeTreeSelected != null)
            {
                OnChangeTreeSelected(sender, e);
            }
        }
    }
}
